using System.Collections;
using UnityEngine;
using UnityEngine.UIElements;
using DG.Tweening;
using System.Security.Cryptography;

public class Basket : MonoBehaviour
{
    public static Vector2 ScoreTextPos;
    public Transform ScoreTextClonePos;
    public static Vector2 screenRight; 
    public bool flip_x = false;

    public AnimationClip MoveOut_L;
    private float moveOutTarget;

    private Animation animation;
    void Start()
    {
        animation = GetComponent<Animation>();
        screenRight = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height)); 
        RandomPos();
    }

    private void Update() {
        if (Input.GetKeyDown(KeyCode.C)) {
            RandomPos();   
        }
    }

    public void RandomPos() 
    {

        float x_pos = 0.0f;
        if (flip_x)
        {
            x_pos = -screenRight.x;
            transform.localScale = new Vector2(-1, 1);
        } else {
            x_pos = screenRight.x;
            transform.localScale = new Vector2(1, 1);
        } 
        float height = Random.Range(-screenRight.y * 0.5f, screenRight.y / 3 * 2);
        transform.position = new Vector2(x_pos, height);
        moveOutTarget = x_pos;
        MoveOut(flip_x);
        flip_x = !flip_x;
    }

    private void MoveOut(bool flip_x)
    {
        if (flip_x)
        {
            transform.position = new Vector2(moveOutTarget - 3, transform.position.y);
            transform.DOMoveX(moveOutTarget, 0.5f);
        }
        else
        {
            transform.position = new Vector2(moveOutTarget + 3, transform.position.y);
            transform.DOMoveX(moveOutTarget, 0.5f);
        }
    }

    
}
